package com.yxt.ui;

import com.yxt.common.ui.ActivityStackControlUtil;
import com.yxt.model.Address;
import com.yxt.service.AddressService;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;  
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 通讯录详细
 * @author TYP
 *
 */
public class AddressDetailActivity extends Activity {
	private AddressService service = new AddressService(AddressDetailActivity.this);
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
		setContentView(R.layout.address_detail);   //软件activity的布局	
		ActivityStackControlUtil.add(this); 
		initComponent();
	}
	
	private void initComponent(){
		Button btnBackHome = (Button)findViewById(R.id.btnBackHome);
		btnBackHome.setOnClickListener(new OnClickListener(){
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), MainActivity.class);
				startActivity(intent);
			}
		});
		Intent intent = getIntent();
		Address addr = service.getAddressById(intent.getStringExtra("addrId"));
		
		TextView lblAddName = (TextView)findViewById(R.id.lblAddName);
		lblAddName.setText(addr.getName());
		TextView lblAddDsfb = (TextView)findViewById(R.id.lblAddDsfb);
		lblAddDsfb.setText(addr.getStb_pcode());
		TextView lblAddFbbm = (TextView)findViewById(R.id.lblAddFbbm);
		lblAddFbbm.setText(addr.getDepartmentid());
		TextView lblAddDwzw = (TextView)findViewById(R.id.lblAddDwzw);
		lblAddDwzw.setText(addr.getJob());
		TextView lblAddFbzw = (TextView)findViewById(R.id.lblAddFbzw);
		lblAddFbzw.setText(addr.getSfjob());
		TextView lblAddOffTel = (TextView)findViewById(R.id.lblAddOffTel);
		final String offtel = addr.getOfficetel();
		lblAddOffTel.setText(offtel);
		TextView lblAddHomeTel = (TextView)findViewById(R.id.lblAddHomeTel);
		final String hometel = addr.getHometel();
		lblAddHomeTel.setText(hometel);
		TextView lblAddTel = (TextView)findViewById(R.id.lblAddTel);
		final String mobiltel = addr.getMobiltel();
		lblAddTel.setText(mobiltel);
		
		ImageView imgOffTel = (ImageView)findViewById(R.id.imgOffTel);	
		if (!"".equals(offtel)) {
			imgOffTel.setOnClickListener(new OnClickListener(){
				public void onClick(View arg0) {
					Intent phone = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+offtel));		
					startActivity(phone);
				}
				
			});
		}
		ImageView imgHomeTel = (ImageView)findViewById(R.id.imgHomeTel);
		if (!"".equals(hometel)) {
			imgHomeTel.setOnClickListener(new OnClickListener(){
				public void onClick(View arg0) {
					Intent phone = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+hometel));		
					startActivity(phone);
				}
				
			});
		}
		ImageView imgPhTel = (ImageView)findViewById(R.id.imgPhTel);
		if (!"".equals(mobiltel)) {
			imgPhTel.setOnClickListener(new OnClickListener(){
				public void onClick(View arg0) {
					Intent phone = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+mobiltel));		
					startActivity(phone);
				}
				
			});
		}
	}

	protected void onDestroy() {
		super.onDestroy();
		service.closeDB();
        ActivityStackControlUtil.remove(this);
	}
}